<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="150px">
        <el-row>
          <!-- <el-col :span="8">
            <el-form-item label="订单号">
              <el-input v-model="form.order_sn" clearable />
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="姓名/手机号">
              <el-input v-model="form.username" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="挂售卡/券">
              <el-input v-model="form.name" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="8">
          <el-form-item label="挂售时间">
            <el-date-picker
              v-model="time"
              type="daterange"
              value-format="timestamp"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
          <Exprotcomponent :params="form" url="admin/sale/export" type="php"></Exprotcomponent>
        </el-col>
      </el-form>
    </div>
    <div class="listDiv">
      <!-- {{$store.state.user.permissionJson}} -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        ></el-table-column>
        <el-table-column label="挂售人姓名" prop="realname" align="center" />
        <el-table-column label="手机号" prop="username" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.username | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column label="挂售卡/券" prop="card_name" align="center" />
        <el-table-column label="订单状态" prop="sale_status" align="center" />
        <el-table-column label="原价" prop="price" align="center" />
        <el-table-column label="挂售价" prop="sale_price" align="center" />
        <el-table-column label="挂售时间" prop="put_start_time" align="center">
          <template slot-scope="scope">{{scope.row.put_start_time*1000 | date(1)}}</template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope" v-if="scope.row.status!=0 ">
            <el-button
              size="small"
              v-if="scope.row.sale_status_type <2"
              type="text"
              @click="status(scope.row)"
            >下架</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="form.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import filter from "@/assets/filter";
//src\api\CtoCshop\index.js
import { list, change_status } from "@/api/CtoCshop/index";
export default {
  name: "",
  watch: {
    time(val) {
      this.form.start_time = val ? val[0] / 1000 : "";
      this.form.end_time = val ? val[1] / 1000 : "";
    }
  },
  data() {
    return {
      time: "",
      total: 0,
      tableData: [{}],
      form: { page: 1, pagesize: 10 }
    };
  },
  created() {
    this.list();
  },
  methods: {
    async status(datas) {
      let res = await change_status({ id: datas.id });
      console.log(res);
      this.$message.warning(res.data.msg);
      if (res.data.code == 200) {
        this.list();
      }
    },
    async list() {
      let res = await list(this.form);

      if (res.data.code == 200) {
        this.tableData = res.data.data;
        this.total = res.data.total;
      }
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.pagesize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.list();
    },
    searchFn() {
      this.form.page = 1;
      this.list();
    },
    table_index(index) {
     
      if (index>=0) {
        return (this.form.page - 1) * this.form.pagesize + index + 1;
      }
    }
  }
};
</script>
